package cl.sodexo.com.dao;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import org.apache.log4j.Logger;

public abstract class AbstractDAO {
	
	private static final Logger logger = Logger.getLogger(AbstractDAO.class);
	
	protected Connection loadConnection(){
		Connection con = null;
		
		try{
			DriverManager.registerDriver(new org.gjt.mm.mysql.Driver());
	        con = DriverManager.getConnection("jdbc:mysql://localhost/psep", "root", "123456");
			
		}catch(Exception e){
			logger.error(e, e);
		}
		
		return con;
	}
	
	protected void closeAll(Connection con, PreparedStatement ps, ResultSet rs){
		if(con != null){
			try {
				con.close();
			} catch (SQLException e) {
				logger.error(e, e);
			}
		}
		
		if(ps != null){
			try {
				ps.close();
			} catch (SQLException e) {
				logger.error(e, e);
			}
		}
		
		if(rs != null){
			try {
				rs.close();
			} catch (SQLException e) {
				logger.error(e, e);
			}
		}
	}

}
